while(1) {
# get mouse click
do {                 
print TO_ABS "-x mouseClick\n";$f=<FROM_ABS>;chomp $f;
#sleep 0.25 seconds  
select(undef, undef, undef, 0.25);
} while ($f==none);

($x1, $y1, $x2, $y2, $mode) = split(' ', $f, 5);

print TO_ABS "-x setFitRange -s$x1 -e$x2\n";

for ($i = 1; $i <=1; $i+=6) {
print TO_ABS "-x selectCurveByIndex -i $i -j$i \n";
print TO_ABS "-x statistic\n";
$text=<FROM_ABS>;
chomp $text;
($n, $min, $max, $sum, $std, $area, $name) = split(' ', $text, 7);

$baseLine = "$x1 $y1\r $x2 $y2";
print TO_ABS "-x replaceData -sBaseLine -p '$baseLine'\n";
$baseArea = ($x2-$x1)*($y1+$y2)/2;
if ($sum>0) {
    $err = sqrt($sum)/$sum*$area;}
else {
   $err = 0;}

$xmean = ($x2+$x1)/2;
$lineArea = $area - $baseArea;
printf "%g   %g  %g\n", $xmean, $lineArea,  $err;
}
}